package com.pay.bean;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;

/**
 * 微信扫码预支付结果。
 * 详情见：https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1
 */
@Getter
@Setter
public class WxPrePayResult extends WxResult implements Serializable {

    //预支付交易会话标识
    private String prepayId;

    //二维码链接
    private String codeUrl;

    //交易类型
    private String tradeType = "NATIVE";

    @Override
    public  Map<Object, Object> initial(Map<String, String> params, String key){
        Map<Object, Object> validParams = super.initial(params, key);
        try {
            if ("SUCCESS".equals(getReturnCode()) && "SUCCESS".equals(getResultCode()) && isSignValid()) {
                setTradeType((String)validParams.get("trade_type"));
                setPrepayId((String) validParams.get("prepay_id"));
                setCodeUrl((String) validParams.get("code_url"));
            }
        }catch (Exception ex){}

        return validParams;
    }
}
